﻿using diary.POCO;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace diary
{
    /// <summary>
    /// Interaction logic for MovieControl.xaml
    /// </summary>
    public partial class MovieControl : UserControl
    {
        public MovieControl()
        {
            InitializeComponent();
            this.DataContext = this;
            FirstColumn.Width = new GridLength(0);
        }

        private Movie _movie;
        public Movie Movie { 
            get 
            {
                return _movie;
            }
            set
            {
                _movie = value;
                if (_movie.Rank > 0)
                {
                    FirstColumn.Width = new GridLength(20);
                }

                BindingOperations.ClearBinding(TxtTitle, TextBox.TextProperty);
                BindingOperations.ClearBinding(TxtYear, TextBox.TextProperty);
                BindingOperations.ClearBinding(lblRank, Label.ContentProperty);

                Binding binding = new Binding { Source = this, Path = new PropertyPath("Movie.Title") };
                TxtTitle.SetBinding(TextBox.TextProperty, binding);
                Binding binding2 = new Binding { Source = this, Path = new PropertyPath("Movie.Year") };
                TxtYear.SetBinding(TextBox.TextProperty, binding2);
                Binding binding3 = new Binding { Source = this, Path = new PropertyPath("Movie.Rank") };
                lblRank.SetBinding(Label.ContentProperty, binding3);
            }
        }
    }
}
